Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve token stability by making the API token a "unique" index. #40

Closed

Conversation

bummzack
Copy link
Contributor

Centralized code that performs token updates (removed duplicate code).
Implemented a test to assert token uniqueness.

See Issue #39

Centralized code that performs token updates (removed duplicate code).
Implemented a test to assert token uniqueness.
$tokenData = $this->generateToken( $expired );

// ensure we never regenerate the same token!
if($owner->{$tokenDBColumn} != $tokenData['token']){
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we use '!==' ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The point where the token would collide is in the Database. So, if we add the type check, do we improve or worsen the stability of the check?

The only distinction on the DB side would be 'null' != null? Otherwise everything should be treated as string (varchar). I think it's sensible to assume both tokens will become strings, so I'd stick with the != check, since checking for type inequality isn't important to the DB... or am I missing something important here?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tokenData should always be a string, so it should be fine to use !== no?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I guess stricter is better here. So using !== is fine.

@colymba
Copy link
Owner

colymba commented Jun 10, 2015

This looks good I think. Only had 2 small questions. Even if fixing edge cases, it's a great security addition. Thx.

@bummzack
Copy link
Contributor Author

This code has issues with MsSQL DBs. Closing this request.

@bummzack bummzack closed this Jun 19, 2015
@colymba
Copy link
Owner

colymba commented Jun 20, 2015

OK.. What was the MsSQL issue?

Also, I do think we should make sure tokens are unique somehow. UUID seem the best solution.

@bummzack
Copy link
Contributor Author

The current implementation of SilverStripe MsSQL bindings creates unique indexes that won't allow multiple NULL values: silverstripe/silverstripe-mssql#24

Thus, declaring the ApiToken column to be unique will fail on MsSQL, since most entries in the Member table will start without an ApiToken value or never get one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants